feat(tui): add manual compact command#716
Conversation
Greptile SummaryThis PR adds
Confidence Score: 3/5The core compaction logic is sound, but the done-callback path writes to TuiLiveView from the event loop thread without any synchronization, which is a new concurrency pattern not present in the existing send flow. The new strix/interface/tui/messages.py — the Important Files Changed
Prompt To Fix All With AIFix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
strix/interface/tui/messages.py:64-79
**Cross-thread mutation of `TuiLiveView` via done callback**
`_record_compaction_result` calls `live_view.record_system_message()` from the event loop thread (done callbacks on `concurrent.futures.Future` run on the thread that set the result, which is the event loop thread for `run_coroutine_threadsafe`). Meanwhile, callers on the TUI input thread can invoke `live_view.record_user_message()` for a subsequent message while compaction is in flight. Both paths write to `TuiLiveView.events` and increment `_next_event_id`, neither of which is protected by a lock. If a second user message arrives before the compaction coroutine finishes, these two writes race, potentially producing duplicate event IDs or a corrupted event list.
### Issue 2 of 3
strix/core/agents.py:158-181
**Misleading log when session is not yet attached**
When `compact_agent_session` is called before `attach_runtime` has set a session, `session` is `None`. The code passes `None` straight to `is_openai_responses_compaction_aware_session`, which will return `False`, causing the log to read "SDK session does not support compaction" — even though the actual problem is that no session is attached at all. The existing `send()` method handles this with an explicit `None` guard and a distinct, accurate message. Without the same guard here, a developer debugging a "compaction not working" report will look at the wrong place.
### Issue 3 of 3
strix/interface/tui/messages.py:71-79
**Exception and "not supported" both surface as "unavailable"**
When `compact_agent_session` raises (e.g., a transient network failure during `run_compaction`), `future.result()` re-raises inside `_record_compaction_result`, `compacted` is set to `False`, and the UI shows `"Context compaction is unavailable for this agent."` — the same message used when the SDK session structurally lacks compaction support. A transient error would mislead the user into thinking compaction is a permanent capability gap rather than something that might succeed on retry.
Reviews (1): Last reviewed commit: "feat(tui): add manual compact command" | Re-trigger Greptile |
|
Addressed the Greptile review feedback in d1ca17d. Summary:
Verified with:
Resolved the three outdated Greptile threads after this fix. |
d1ca17d to
2e36db7
Compare
44e87ca to
daf39a2
Compare
Summary
Fix #680
/compactand/compresshandling in the interactive TUI message path.Test verification (RED -> GREEN)
RED check with production files reverted:
uv run pytest tests/test_manual_compact.py -qResult:
3 failed; the coordinator lackedcompact_agent_session, and slash commands were not routed to compaction.GREEN check with fix applied:
uv run pytest tests/test_manual_compact.py tests/test_execution.py -qResult:
6 passed.Additional checks
uv run ruff check strix/core/agents.py strix/interface/tui/messages.py strix/interface/tui/live_view.py tests/test_manual_compact.pyuv run ruff format --check strix/core/agents.py strix/interface/tui/messages.py strix/interface/tui/live_view.py tests/test_manual_compact.pyuv run mypy strix/coreGenerated by Ora Studio
Vibe coded by ousamabenyounes